interface IPageData {
  isPublic: boolean;
  myCreations: Array<{
    id: number;
    title: string;
    imageUrl: string;
    createTime: string;
  }>;
}

Page<IPageData>({
  data: {
    isPublic: false,
    myCreations: [
      {
        id: 1,
        title: '神奇的树屋',
        imageUrl: 'https://images.unsplash.com/photo-1741290606668-c367b34d3d4a?q=80&w=1974&auto=format&fit=crop&ixlib=rb-4.0.3',
        createTime: '2024-01-20'
      },
      {
        id: 2,
        title: '月亮上的小屋',
        imageUrl: 'https://images.unsplash.com/photo-1658238134097-ee857daef354?q=80&w=1974&auto=format&fit=crop&ixlib=rb-4.0.3',
        createTime: '2024-01-18'
      }
    ]
  },

  chooseImage() {
    wx.chooseMedia({
      count: 1,
      mediaType: ['image'],
      sourceType: ['album', 'camera'],
      success: (res) => {
        const tempFilePath = res.tempFiles[0].tempFilePath;
        // 上传图片并进行OCR识别
        this.uploadAndProcessImage(tempFilePath);
      }
    });
  },

  uploadAndProcessImage(filePath: string) {
    // TODO: 实现图片上传和OCR处理逻辑
    wx.showLoading({ title: '处理中...' });
    // 模拟上传处理过程
    setTimeout(() => {
      wx.hideLoading();
      wx.showToast({
        title: '识别成功',
        icon: 'success'
      });
    }, 2000);
  },

  selectTag(event: WechatMiniprogram.TouchEvent) {
    const tag = event.currentTarget.dataset.tag;
    // TODO: 处理标签选择逻辑
  },

  togglePublic() {
    this.setData({
      isPublic: !this.data.isPublic
    });
  },

  startCreate() {
    // TODO: 实现AI故事生成逻辑
    wx.showLoading({ title: '创作中...' });
    setTimeout(() => {
      wx.hideLoading();
      wx.navigateTo({
        url: '/pages/story/story?id=new'
      });
    }, 2000);
  },

  viewAllCreations() {
    wx.navigateTo({
      url: '/pages/creations/creations'
    });
  },

  viewCreation(event: WechatMiniprogram.TouchEvent) {
    const creationId = event.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/story/story?id=${creationId}`
    });
  },

  onShareAppMessage() {
    return {
      title: '童话大全 - 创作中心',
      path: '/pages/create/create'
    };
  }
});